package com.scujj.pojo;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class WsResult {
    private int code;
    private String event;
    private Object data;

    public static String json(Object obj,int c,String e){
        try {
            return JSON.toJSONString(new WsResult(c,e,obj));
        }catch (Exception exception){
            System.out.println("转json导致错误时的obj:"+obj.toString());
            exception.printStackTrace();
        }
        return "error";
    }

    public static String json(Object obj,String e){
        return JSON.toJSONString(new WsResult(0,e,obj));
    }

    public static String err(){
        return JSON.toJSONString(new WsResult(-1,null,null));
    }

    public static WsResult result(Object obj,int c,String e){
        return new WsResult(c,e,obj);
    }

    public static WsResult result(Object obj,String e){
        return new WsResult(0,e,obj);
    }

}
